package com.prg.action.app.initLift;

import com.prg.action.app.BaseController;
import com.prg.model.base.AuthMenu;
import com.prg.model.easyui.Grid;
import com.prg.model.easyui.Json;
import com.prg.model.easyui.Tree;
import com.prg.service.LeftTreeService;
import com.prg.util.HqlFilter;
import com.prg.util.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 15-1-2
 * Time: 下午3:40
 * To change this template use File | Settings | File Templates.
 */
@Controller
@RequestMapping("/initleft")
public class InitLeftMneuTreeController extends BaseController<AuthMenu> {
    @Autowired
    private LeftTreeService leftTreeService;
    /**
     * 初始化左侧菜单树异步
     */
    @RequestMapping("/gettree")
    public void initLeftTree(String id,HttpServletResponse response){
        List treelist= leftTreeService.getLiftTree(id);
        JsonUtil.writeJson(response ,treelist);
    }

    /**
     * 非异步
     */
    @RequestMapping("/gettreeall")
    public void initLeftTreeAll(HttpServletResponse response){
        List<Tree> treeList=leftTreeService.getLiftTreeAll();
        JsonUtil.writeJson(response,treeList);

    }
    /**
     * 初始化资源管理页面异步
     */
    @RequestMapping("/gettreegrid")
    public void getMenuTreeGrid(String id,HttpServletResponse response){
        List treelist= leftTreeService.getMenuTreeGrid(id);
        JsonUtil.writeJson(response ,treelist);
    }

    @RequestMapping("/savemenu")
    public void saveMenu(HttpServletResponse response,AuthMenu menu){
        Json json = new Json();
        if (menu != null) {
            leftTreeService.saveMenu(menu);
            json.setSuccess(true);
            json.setMsg("新建成功！");
        }
        JsonUtil.writeJson(response,json);


    }
    @RequestMapping("/editmenu")
    public void editMenu(HttpServletResponse response,AuthMenu menu){

        Json json = new Json();
        if (menu != null) {
            leftTreeService.updateMenu(menu);
            json.setSuccess(true);
            json.setMsg("新建成功！");
        }
        JsonUtil.writeJson(response,json);



    }
    @RequestMapping("/deletemenu")
    public void deleteMenu(HttpServletResponse response,AuthMenu menu){
        this.delete(response,leftTreeService,menu);


    }

    @RequestMapping("/listmenu")
    public void getMenu(HttpServletResponse response){
        Json msg=new Json();
        List l= leftTreeService.find("from AuthMenu");
        msg.setObj(l);
        JsonUtil.writeJson(response,msg);
    }
    /**
     * 查找分页后的grid
     */
    @RequestMapping("/grid")
    public void grid(HttpServletRequest request,HttpServletResponse response) {
        leftTreeService.getAuthMenu(request,response,leftTreeService);

    }
}
